package com.game.commons.scripts.java.scriptmanager;

import java.io.File;
import java.util.List;

import javax.xml.bind.annotation.XmlAccessType;
import javax.xml.bind.annotation.XmlAccessorType;
import javax.xml.bind.annotation.XmlAttribute;
import javax.xml.bind.annotation.XmlElement;
import javax.xml.bind.annotation.XmlRootElement;

import com.game.commons.scripts.java.impl.javacompiler.ScriptCompilerImpl;



/**
 * 脚本信息表
 * 包含脚本的根目录，脚本的子目录，库列表，脚本加载卸载实现类
 * @author 杜祥
 * @create 2013-6-26
 */
@XmlRootElement(name = "scriptinfo")
@XmlAccessorType(XmlAccessType.NONE)
public class ScriptInfo 
{
	/**
	 * 脚本的跟目录
	 */
	@XmlAttribute(required = true)
	private File root;
	
	/**
	 * 库列表
	 */
	@XmlElement(name = "library")
	private List<File> libraries;
	
	
	/**
	 * 子脚本信息
	 */
	@XmlElement(name = "scriptinfo")
	private List<ScriptInfo> scriptInfos;
	
	
	/**
	 * 脚本编译器类名，默认为ScriptComilerImpl
	 */
	@XmlElement(name = "compiler")
	private String compilerClass = ScriptCompilerImpl.class.getName();


	public File getRoot() 
	{
		return root;
	}


	public void setRoot(File root) 
	{
		this.root = root;
	}


	public List<File> getLibraries() 
	{
		return libraries;
	}


	public void setLibraries(List<File> libraries) 
	{
		this.libraries = libraries;
	}


	public List<ScriptInfo> getScriptInfos()
	{
		return scriptInfos;
	}


	public void setScriptInfos(List<ScriptInfo> scriptInfos) 
	{
		this.scriptInfos = scriptInfos;
	}


	public String getCompilerClass() 
	{
		return compilerClass;
	}


	public void setCompilerClass(String compilerClass) 
	{
		this.compilerClass = compilerClass;
	}

	/**
	 * {@inheritDoc}
	 */
	@Override
	public int hashCode() 
	{
		return root.hashCode();
	}

	/**
	 * {@inheritDoc}
	 */
	@Override
	public boolean equals(Object o)
	{
		if(this == o)
			return true;
		if(o == null || getClass() != o.getClass())
			return false;

		ScriptInfo that = (ScriptInfo) o;

		return root.equals(that.root);
	}

	/**
	 * {@inheritDoc}
	 */
	@Override
	public String toString() 
	{
		final StringBuilder sb = new StringBuilder();
		sb.append("ScriptInfo");
		sb.append("{root=").append(root);
		sb.append(", libraries=").append(libraries);
		sb.append(", compilerClass='").append(compilerClass).append('\'');
		sb.append(", scriptInfos=").append(scriptInfos);
		sb.append('}');
		return sb.toString();
	}
	
}
